< previous page page_168 next page >

Page 168
    Case 0
        MsgBox The Value is Zero
    Case 1,3,5,7,9
        MsgBox The Value is Odd
    Case 2,4,6,8,10
        MsgBox The Value is Even
    Case Else
        MsgBox The number is invalid
End Select
Again, depending on what you need for your application, the Select Case statement would be very useful for testing values being input into the application.
Other Functions
Finally, two other functions are worth mentioning in this section:
ChooseSelects and returns a value from a list of arguments based on an index value.
IIfReturns one of two values depending on the expression.
Each of these functions provides a unique method of choosing a particular value or expression. The Choose function enables you to use an index value to select from a list of strings or numbers. This works particularly if the index represents the value in an option group. The following is the syntax of the Choose function:
Choose(index, choice-1[, choice-2,  [, choice-n]])
This function will enable you to choose from as many different values as you need to include in the parameter list. Using the Choose function is quite easy. The following is an example of how to use it:
Shipper = Choose(index, FedEx, Airborne, DHL)
If the index value is between 1 and 3, the appropriate string will be placed in the variable Shipper. If the index value is less than 1 or greater than the number of choices from which it must choose, it will return a Null value.
The other function, IIf, will return one of two expressions, depending on the value of a conditional expression. The following is the syntax of this function:
IIf (expr, truepart, falsepart)
This function is also fairly easy to use. This function represents the old two-door method of choosing. If the expr is true, the first value or expression is returned; if the expr is false, the second one is returned. This function could be used to calculate a discount based on a single condition as shown here:

 
< previous page page_168 next page >

If you like this book, buy it!